package edu.wayne.cs.csc4110.hw6.framework.message;

import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

import edu.wayne.cs.csc4110.hw6.interfaces.message.Message;
import edu.wayne.cs.csc4110.hw6.interfaces.user.User;

public class LobbyMessage implements Message {

	public User getSender() {
		return sender;
	}

	private SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm:ss");
	private String msg;
	private User sender;
	private Date date;

	public LobbyMessage(User sender, String msg) {
		this.sender = sender;
		this.msg = msg;
		this.date = new Date();
	}

	@Override
	public String getMessage() {
		// TODO Auto-generated method stub
		return msg;
	}

	@Override
	public void write(OutputStream out) {
		try {
			out.write(msg.getBytes());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	@Override
	public String getFormatedMessage() {

		return "[" + timeFormat.format(date) + "]<" + sender.getUsername()
				+ ">" + msg;
	}

}
